package com.kamco.cd.kamcoback.postgres.entity;

import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Category;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Species;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

// 기본구조 관련

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "tb_animal")
public class AnimalEntity extends CommonDateEntity {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long uid;

  @Column(unique = true)
  private UUID uuid;

  @Enumerated(EnumType.STRING)
  private Category category;

  @Enumerated(EnumType.STRING)
  private Species species;

  private String name;
  private Boolean isDeleted;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "zoo_id")
  private ZooEntity zoo;

  // Construct
  public AnimalEntity(Category category, Species species, String name, ZooEntity zoo) {
    this.uuid = UUID.randomUUID();
    this.category = category;
    this.species = species;
    this.name = name;
    this.isDeleted = false;
    this.zoo = zoo;
  }

  public AnimalDto.Basic toDto() {
    return new AnimalDto.Basic(
        this.uid,
        this.uuid.toString(),
        this.name,
        this.category,
        this.species,
        super.getCreatedDate(),
        super.getModifiedDate());
  }

  public void deleted() {
    this.isDeleted = true;
  }
}
