package com.izouma.wenlvju.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import com.izouma.wenlvju.domain.Record;
import com.izouma.wenlvju.domain.RecordExpert;
import com.izouma.wenlvju.domain.RecordSpecialty;
import com.izouma.wenlvju.utils.excel.BooleanConverter;
import com.izouma.wenlvju.utils.excel.LocalDateConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "Record Management")
public class RecordDTO extends BaseRowModel {
    @ExcelProperty(value = "备案序号", index = 0)
    private long no;

    @ExcelProperty(value = "考级活动名称", index = 1)
    private String examinationName;

    @ExcelProperty(value = "考级活动时间", index = 2, converter = LocalDateConverter.class)
    private LocalDate examinationStartTime;

    @ExcelProperty(value = "考级活动时间", index = 3, converter = LocalDateConverter.class)
    private LocalDate examinationEndTime;

    @ExcelProperty(value = "考级机构名称", index = 4)
    private String examinationAgency;

    @ExcelProperty(value = "单位类别", index = 5)
    private String category;

    @ExcelProperty(value = "承办单位名称", index = 6)
    private String organizer;

    @ExcelProperty(value = "统一社会信用代码", index = 7)
    private String uscc;

    @ExcelProperty(value = "考级地址", index = 8)
    private String district;

    @ExcelProperty(value = "考级详细地址", index = 9)
    private String examinationAddress;

    @ExcelProperty(value = "考场数量", index = 10)
    private int examCenterQuantity;

    @ExcelProperty(value = "报考人数", index = 11)
    private int examQuantity;

    @ExcelProperty(value = "考官人数", index = 12)
    private int examinerQuantity;

    @ExcelProperty(value = "考点负责人名称", index = 13)
    private String examOwner;

    @ExcelProperty(value = "考点负责人手机号", index = 14)
    private String examOwnerPhone;

    @ExcelProperty(value = "安全负责人名称", index = 15)
    private String securityOwner;

    @ExcelProperty(value = "安全负责人手机号", index = 16)
    private String securityOwnerPhone;

    @ExcelProperty(value = "备案时间", index = 17, converter = LocalDateConverter.class)
    private LocalDate recordTime;

    @ExcelProperty(value = "考试简章", index = 18)
    private String examinationGuide;

    @ExcelProperty(value = "考级专业序号", index = 19)
    private Long sno;

    @ExcelProperty(value = "考级专业名称", index = 20)
    private String name;

    @ExcelProperty(value = "考级专业代码", index = 21)
    private String code;

    @ExcelProperty(value = "考级专业总级数", index = 22)
    private String level;

    @ExcelProperty(value = "考级专业考场数量", index = 23)
    private int numOfExam;

    @ExcelProperty(value = "考级专业考官人数", index = 24)
    private int speExaQuantity;

    @ExcelProperty(value = "考官姓名", index = 25)
    private String expertName;

    @ExcelProperty(value = "考官性别", index = 26)
    private String sex;

    @ExcelProperty(value = "证件号码", index = 27)
    private String idNo;

    @ExcelProperty(value = "是否外聘", index = 28, converter = BooleanConverter.class)
    private Boolean external;

    @ExcelProperty(value = "职称", index = 29)
    private String position;

    public RecordDTO(Record record, RecordSpecialty specialty, RecordExpert expert, long no, Long sno) {
        BeanUtil.copyProperties(record, this);
        this.examinerQuantity = record.getExaminerQuantity();

        if (ObjectUtil.isNotEmpty(specialty)) {
            BeanUtil.copyProperties(specialty, this);
            this.speExaQuantity = specialty.getExaminerQuantity();
        }

        if (ObjectUtil.isNotEmpty(expert)) {
            BeanUtil.copyProperties(expert, this);
            this.expertName = expert.getName();
        }
        this.no = no;
        this.sno = sno;
    }
}
