package com.ruoyi.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.ruoyi.demo.entity.bo.PlanAddBo;
import com.ruoyi.demo.utils.OnStateUtil;
import com.ruoyi.demo.utils.StateUtil;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

@Data
@TableName("dl_plan")
public class Plan {
    @TableId(value = "plan_id",type = IdType.ASSIGN_ID)
    private String planId;

    @TableField("plan_name")
    private String planName;

    @TableField("commercial_id")
    private String commercialId;
    @TableField("commercial_name")
    private String commercialName;
    @TableField("appkey")
    private String appkey;
    @TableField("app_name")
    private String appName;

    @TableField("vendor_id")
    private String vendorId;
    @TableField("vendor_name")
    private String vendorName;

    @TableField("goods_id")
    private String goodsId;
    @TableField("goods_img")
    private String goodsImg;
    @TableField("goods_name")
    private String goodsName;
    @TableField("goods_logo")
    private String goodsLogo;
    @TableField("goods_introduce")
    private String goodsIntroduce;
    @TableField("goods_price")
    private Float goodsPrice;
    @TableField("goods_classify")
    private String goodsClassify;
    @TableField("plan_create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime planCreateTime;
    @TableField("plan_start_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime planStartTime;
    @TableField("plan_end_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime planEndTime;
    @TableField("state")
    private Integer state;

    @TableField("on_state")
    private Integer onState;
    @TableField("principal_name")
    private String principalName;
    @TableField("principal_telephone")
    private String principalTelephone;

    @TableField("deleted")
    private int deleted;

    public Plan(){}
    public Plan(App app, PlanAddBo bo){
        this.setCommercialId(app.getCommercialId());
        this.setCommercialName(app.getCommercialName());
        this.setAppkey(app.getAppkey());
        this.setAppName(app.getAppName());

        this.setPlanName(bo.getPlanName());

        this.setVendorId(bo.getVendorId());
        this.setVendorName(bo.getVendorName());

        this.setGoodsId(bo.getGoodsId());
        this.setGoodsImg(bo.getGoodsImg());
        this.setGoodsName(bo.getGoodsName());
        this.setGoodsLogo(bo.getGoodsLogo());
        this.setGoodsPrice(bo.getGoodsPrice());
        this.setGoodsIntroduce(bo.getGoodsIntroduce());
        this.setGoodsClassify(bo.getGoodsClassify());
        this.setPlanCreateTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
        this.planStartTime = bo.getPlanStartTime();
        this.planEndTime = bo.getPlanEndTime();
        this.setState(StateUtil.NOT_AUDITED);

        this.setOnState(OnStateUtil.UP);
        this.setPrincipalName(bo.getPrincipalName());
        this.setPrincipalTelephone(bo.getPrincipalTelephone());
    }
}
