package kr.co.accura.wtm.domain.approval.entity;

import jakarta.persistence.*;
import kr.co.accura.wbx.spring.common.BaseEntity;
import lombok.*;

import java.time.LocalDateTime;

@Entity
@Table(name = "approval_lines")
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TtApprovalLine extends BaseEntity {

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "approval_id", nullable = false)
    private TtApproval approval;

    @Column(name = "approver_id", nullable = false)
    private Long approverId;

    @Column(name = "approval_order", nullable = false)
    private int approvalOrder;

    @Column(name = "role_code", length = 20)
    private String roleCode;

    @Column(length = 20)
    @Builder.Default
    private String status = "PENDING";

    @Column(name = "acted_at")
    private LocalDateTime actedAt;

    public void approve() {
        this.status = "APPROVED";
        this.actedAt = LocalDateTime.now();
    }

    public void reject() {
        this.status = "REJECTED";
        this.actedAt = LocalDateTime.now();
    }
}
