package com.izouma.wenlvju.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.izouma.wenlvju.domain.Organization;
import com.izouma.wenlvju.domain.Rate;
import com.izouma.wenlvju.enums.RateStatus;
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.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel(value = "Rate")
public class RateDTO {
    @ExcelIgnore
    private Long id;

    @ExcelProperty(value = "编号")
    private String code;

    @ExcelProperty(value = "承办单位名称")
    @ApiModelProperty(value = "承办单位名称")
    private String name;

    @ExcelProperty(value = "申请时间")
    private LocalDateTime createdAt;

    @ExcelIgnore
    private String district;

    @ExcelIgnore
    private RateStatus status;

    @ExcelProperty(value = "审核状态")
    private String status1;

    @ExcelIgnore
    @ApiModelProperty(value = "单位概况")
    private String introduction;

    @ExcelIgnore
    @ApiModelProperty(value = "是否提交")
    private boolean submit;

    @ApiModelProperty(value = "是否承办考级活动")
    private boolean undertakeExamination;

//    @ApiModelProperty(value = "承办单位")
//    private String organizer;

    @ExcelProperty(value = "地址")
    private String address;


    @ExcelProperty(value = "年度")
    @ApiModelProperty(value = "年度")
    private String year;

    @ExcelProperty(value = "考级机构名称")
    @ApiModelProperty(value = "考级机构名称")
    private String gradingOrganization;

    @ExcelIgnore
    @ApiModelProperty(value = "申请时间")
    private LocalDateTime applyTime;

    @ExcelProperty(value = "总分")
    @ApiModelProperty(value = "分数")
    private int score;

    @ExcelProperty(value = "等级")
    @ApiModelProperty(value = "等级")
    private String grade;

    @ExcelIgnore
    @ApiModelProperty(value = "驳回时间")
    private LocalDateTime rejectedAt;

    public RateDTO(Rate rate, Organization organization, String gradingOrganization) {
        BeanUtil.copyProperties(rate, this);
        if (ObjectUtil.isNotEmpty(organization)) {
            this.gradingOrganization = gradingOrganization;
            this.code = organization.getCode();
            String address = "南京市" + organization.getDistrict();
            if (StrUtil.isNotBlank(organization.getAddress())) {
                address += organization.getAddress();
            }
            this.address = address;
        }
        if (ObjectUtil.isNotNull(rate.getGrade())) {
            this.grade = rate.getGrade().getDesc();
        }
        if (ObjectUtil.isNotNull(rate.getStatus())) {
            this.status1 = rate.getStatus().getDesc();
        }
    }
}
