package com.cool.store.vo.visit;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.cool.store.annotation.DictField;
import com.cool.store.constants.CommonConstants;
import com.cool.store.enums.visit.VisitStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * <p>
 * 拜访记录列表VO
 * </p>
 *
 * @author wangff
 * @since 2025/12/9
 */
@Data
public class VisitRecordListVO {
    @ApiModelProperty("id")
    @ExcelIgnore
    private Long id;

    @ApiModelProperty(value = "线索id", hidden = true)
    @ExcelIgnore
    private Long lineId;

    @ApiModelProperty("加盟商姓名")
    @ExcelProperty(value = "加盟商姓名", order = 1)
    @ColumnWidth(30)
    private String name;

    @ApiModelProperty("加盟商手机号")
    @ExcelProperty(value = "加盟商手机号", order = 2)
    @ColumnWidth(30)
    private String mobile;

    @ApiModelProperty("拜访编号")
    @ExcelProperty(value = "拜访编号", order = 7)
    @ColumnWidth(30)
    private String visitNo;

    @ApiModelProperty("拜访日期")
    @ExcelProperty(value = "拜访日期", order = 8)
    @ColumnWidth(30)
    private Date visitDate;

    @ApiModelProperty("签到地址")
    @ExcelProperty(value = "拜访地址", order = 9)
    @ColumnWidth(30)
    private String signInAddress;

    @ApiModelProperty("开新店意愿")
    @ExcelIgnore
    private String desire;

    @ApiModelProperty("开新店意愿名称")
    @DictField
    @ExcelProperty(value = "开新店意愿", order = 10)
    @ColumnWidth(30)
    private String desireName;

    @ApiModelProperty("意向开店城市")
    @ExcelIgnore
    private String desireCity;

    @ApiModelProperty("意向开店城市名称")
    @ExcelProperty(value = "意向开店城市", order = 11)
    @ColumnWidth(30)
    private String desireCityName;

    @ApiModelProperty("具体区域")
    @ExcelIgnore
    private String desireDistrict;

    @ApiModelProperty("具体区域名称")
    @ExcelProperty(value = "具体区域", order = 15)
    @ColumnWidth(30)
    private String desireDistrictName;

    @ApiModelProperty("是否对应现有铺位")
    @ExcelIgnore
    private Integer existingShopPoint;

    @ApiModelProperty("是否对应现有铺位")
    @ExcelProperty(value = "是否对应现有铺位", order = 16)
    @ColumnWidth(30)
    private String existingShopPointConvert;

    @ApiModelProperty("加盟商合影图片列表")
    @ExcelProperty(value = "加盟商合影", order = 18)
    @ColumnWidth(30)
    private String photos;

    @ApiModelProperty("拜访状态")
    @ExcelIgnore
    private Integer status;

    @ApiModelProperty("拜访状态名称")
    @ExcelProperty(value = "状态", order = 17)
    @ColumnWidth(30)
    private String statusName;

    @ApiModelProperty("新老加盟商，0新 1老")
    @ExcelIgnore
    private Integer isVeteran;

    @ApiModelProperty("新老加盟商")
    @ExcelProperty(value = "新老加盟商", order = 5)
    @ColumnWidth(30)
    private String isVeteranConvert;

    @ApiModelProperty("拜访人userId")
    @ExcelIgnore
    private String visitUserId;

    @ApiModelProperty("拜访人")
    @ExcelProperty(value = "拜访人", order = 6)
    @ColumnWidth(30)
    private String visitUserName;

    @ApiModelProperty("招商所属大区ID")
    @ExcelIgnore
    private Long investRegionId;

    @ApiModelProperty("招商所属大区名称")
    @ExcelProperty(value = "招商所属大区", order = 3)
    @ColumnWidth(30)
    private String investRegionName;

    @ApiModelProperty("招商经理")
    @ExcelIgnore
    public String investmentManager;

    @ApiModelProperty("招商经理名称")
    @ExcelProperty(value = "招商经理", order = 4)
    @ColumnWidth(30)
    private String investmentManagerName;

    public String getStatusName() {
        return VisitStatusEnum.getDescByStatus(status);
    }

    public String getExistingShopPointConvert() {
        return CommonConstants.INDEX_ONE.equals(existingShopPoint) ? "是" : "否";
    }

    public String getIsVeteranConvert() {
        return CommonConstants.INDEX_ONE.equals(isVeteran) ? "老" : "新";
    }

    public static class VeteranConverter implements Converter<Integer> {

        @Override
        public Class<?> supportJavaTypeKey() {
            return Integer.class;
        }

        @Override
        public CellDataTypeEnum supportExcelTypeKey() {
            return CellDataTypeEnum.STRING;
        }

        @Override
        public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            String value = cellData.getStringValue();
            return "新".equals(value) ? 0 : 1;
        }

        @Override
        public CellData<?> convertToExcelData(Integer isVeteran, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            if (isVeteran == null) {
                return new CellData<>("");
            }
            return new CellData<>(CommonConstants.INDEX_ZERO.equals(isVeteran) ? "新" : "老");
        }
    }
}
