package com.alterdekim.game.entity;

import com.alterdekim.game.controller.result.api.ApiResult;
import com.alterdekim.game.controller.result.api.LocationObjectInstanceResult;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Table(name = "location_objects")
@Entity
public class LocationObjectInstance implements ApiResult {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JacksonXmlProperty(isAttribute = true, localName = "ID")
    private Long id;

    @JacksonXmlProperty(isAttribute = true, localName = "AObjectTypeId")
    @Column(nullable = false)
    private Integer objectTypeId;

    @JacksonXmlProperty(isAttribute = true, localName = "AObjectId")
    @Column(nullable = false)
    private Integer objectId;

    @JacksonXmlProperty(isAttribute = true, localName = "AObjectRefId")
    @Column(nullable = false)
    private Integer objectReferenceId;

    @JacksonXmlProperty(isAttribute = true, localName = "MediaResourceID")
    @Column(nullable = false)
    private Long mediaResourceId;

    @JsonIgnore
    @Column(nullable = false)
    private Long locationId;

    @JacksonXmlProperty(isAttribute = true, localName = "x")
    @Column(nullable = false)
    private Double x;

    @JacksonXmlProperty(isAttribute = true, localName = "y")
    @Column(nullable = false)
    private Double y;

    @JacksonXmlText
    @Column(nullable = false)
    private String options;

    @JsonIgnore
    @Column(nullable = false)
    private String comment;

    @JacksonXmlProperty(isAttribute = true, localName = "Frame")
    private Integer frame;

    @Override
    public LocationObjectInstanceResult toAPIResult() {
        return new LocationObjectInstanceResult(this.id, this.objectTypeId, this.objectId, this.objectReferenceId, this.mediaResourceId, this.locationId, this.x, this.y, this.options, this.comment);
    }

    public LocationObjectInstance(Integer objectTypeId, Integer objectId, Integer objectReferenceId, Long mediaResourceId, Long locationId, Double x, Double y, String options, String comment) {
        this.objectTypeId = objectTypeId;
        this.objectId = objectId;
        this.objectReferenceId = objectReferenceId;
        this.mediaResourceId = mediaResourceId;
        this.locationId = locationId;
        this.x = x;
        this.y = y;
        this.options = options;
        this.comment = comment;
    }
}
