package com.izouma.wenlvju.dto;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.izouma.wenlvju.annotations.EnumFormat;
import com.izouma.wenlvju.domain.VideoObject;
import com.izouma.wenlvju.domain.performance.Participant;
import com.izouma.wenlvju.domain.performance.Programme;
import com.izouma.wenlvju.enums.CompetitionGroup;
import com.izouma.wenlvju.utils.excel.EnumExcelConverter;
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 javax.persistence.EnumType;
import javax.persistence.Enumerated;
import java.time.LocalDate;

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

    @ExcelProperty(value = "活动名称")
    private String performance;

    @ExcelProperty(value = "节目名称")
    private String name;

    @ExcelProperty(value = "参赛专业")
    private String specialty;

    @EnumFormat(value = CompetitionGroup.class,
            fromExcel = {"单人", "集体"},
            toJavaEnum = {"SINGLE", "COLLECTIVE"})
    @ExcelProperty(value = "参赛组别", converter = EnumExcelConverter.class)
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "参赛组别")
    private CompetitionGroup competitionGroup;

    @ExcelProperty(value = "参赛级别")
    private String level;

    @ExcelProperty(value = "作品时长")
    private int durationOfWork;

    @ExcelProperty(value = "指导老师")
    private String instructor;

    @ExcelProperty(value = "联系人")
    private String contact;

    @ExcelProperty(value = "联系电话")
    private String phone;

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

    @ExcelProperty(value = "承办单位")
    private String organization;

    @ExcelProperty(value = "考级点")
    private String examPoint;

    @ExcelProperty(value = "参赛人数")
    private int quantity;

    @ExcelProperty(value = "参赛视频")
    private String video;

    @ExcelIgnore
    private int status;

    @ExcelProperty(value = "照片")
    private String img;

    @ExcelProperty(value = "参赛人员姓名")
    private String participantName;

    @ExcelProperty(value = "参赛人员性别")
    private String participantSex;

    @ExcelProperty(value = "参赛人员出生年月", converter = LocalDateConverter.class)
    private LocalDate participantBirthday;

    @ExcelProperty(value = "参赛人员联系方式")
    private String participantPhone;

    @ExcelProperty(value = "证件号码")
    @ApiModelProperty(value = "证件号码")
    private String idNo;

    @ExcelProperty(value = "证书")
    private String certificate;

    public ProgrammeDTO(Programme programme) {
        BeanUtil.copyProperties(programme, this);
        if (programme.getVideo() != null){
            this.video = programme.getVideo().getSrc();
        }

    }

    public void setParticipant(Participant participant) {
        this.participantName = participant.getName();
        this.participantSex = participant.getSex();
        this.participantBirthday = participant.getBirthday();
        this.participantPhone = participant.getPhone();
        this.idNo = participant.getIdNo();
        this.certificate = participant.getCertificate();
    }
}
