package cn.lihongjie.coal.deviceWorkOrder.dto;

import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.device.entity.DeviceEntity;
import cn.lihongjie.coal.deviceWorkOrderDetail.dto.DeviceWorkOrderDetailDto;
import cn.lihongjie.coal.user.entity.UserEntity;

import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;

import lombok.Data;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class DeviceWorkOrderDto extends OrgCommonDto {

    @Comment("提单人名称")
    private String proposerName;

    @Comment("提单人联系方式")
    private String proposerContact;


    @ManyToOne
    private DeviceEntity device;

    @Comment("工单时间")
    private LocalDateTime time;

    @Comment("工单类型")
    private String type;

    @Formula(
            "(select i.name\n"
            + "from t_dictionary d,\n"
            + "     t_dictionary_item i\n"
            + "where d.id = i.dictionary_id\n"
            + "  and d.code = 'device.workOrder.type'\n"
            + "  and i.code = type)")
    private String typeName;

    @Comment("工单状态")
    private String orderStatus;

    @Formula(
            "(select i.name\n"
            + "from t_dictionary d,\n"
            + "     t_dictionary_item i\n"
            + "where d.id = i.dictionary_id\n"
            + "  and d.code = 'device.workOrder.status'\n"
            + "  and i.code = order_status)")
    private String orderStatusName;

    @Comment("归档状态")
    @ColumnDefault("'0'")
    private String archiveStatus;

    @Formula(
            "(select i.name\n"
            + "from t_dictionary d,\n"
            + "     t_dictionary_item i\n"
            + "where d.id = i.dictionary_id\n"
            + "  and d.code = 'archiveStatus'\n"
            + "  and i.code = archive_status)")
    private String archiveStatusName;


    private List<DeviceWorkOrderDetailDto> details;


    @OneToMany
    private List<UserEntity> workers;
}
