import type { FormRules } from 'element-plus'

/**
 * order实体
 * 只是一个类型说明
 */
export default interface Order{
  detailInfoVos:any,
  createTime: Date | null,
  updateTime: Date | null,
  values: {},
  id: number,
  orderCode: string,
  sellerOrderCode: string,
  sellerId: number,
  sellerName: string,
  vendorId: number,
  vendorName: string,
  toEmail: string
  toMobile: string
  toName: string
  toAddress1: string,
  toAddress2: string
  toRoom:string,
  toCity: string,
  toState: string,
  toZip: string,
  totalAmount: number,
  freezeAmount: number,
  skuCount: number,
  totalCount: number,
  longLabelCode: string
  labelCode: string
  balanceId: number,
  orderStatus: string,
  payStatus: string,
  shipStatus: string,
  orderTime: Date | null,
  paidTime: Date | null
}
export interface Order2 {
  id: number
  orderMonth: string
  serviceProvider: string
  serviceType: string
  orderDay: string
  orderMethod: string
  orderStatus: string
  customerId: number
  customerName: string
  customerRemark: string
  fromEmail: string
  fromMobile: string
  fromFamilyName: string
  fromFirstName: string
  fromAddress1: string
  fromAddress2: string
  fromRoom: string
  fromCity: string
  fromState: string
  fromCountry: string
  fromZip: string
  toEmail: string
  toMobile: string
  toName: string
  toAddress1: string
  toAddress2: string
  toRoom: string
  toCity: string
  toState: string
  toCountry: string
  toZip: string
  labelCodeOrigin: string
  labelCode: string
  labelType: string
  labelUrl: string
  labelTime: Date | null
  packageCmLength: number
  packageCmWidth: number
  packageCmHeight: number
  packageCm3: number
  weightkg: number
  weight: number
  unit: string
  orderId: string
  myOrderId: string
  rootOrderId: string
  sdkOrderId: string
  trackingHandleStatus: string
  trackStatus: string
  trackTime: Date | null
  trackLatest: string
  innerRemark: string
  sku: string
  testing: string
  cancelTime: Date | null
  refundTime: Date | null
  giveupTime: Date | null
  refundReason: string
  addToAddress: string
}

export interface orderSummaryType {
  allOrderCount:number;
  initCount:number;
  outCount:number;
  waitoutCount: number;
  preoutCount: number;
  exceptionCount: number;
  cancelCount: number;
}

/**
 * order校验规则
 * 参考:
 * 1) https://element-plus.gitee.io/zh-CN/component/form.html#%E8%A1%A8%E5%8D%95%E6%A0%A1%E9%AA%8C
 * 2) https://github.com/yiminghe/async-validator
 */
export const orderRules = reactive<FormRules>({
  orderMethod: [{ required: true, message: 'Order Method is required', trigger: 'blur' }],
  orderStatus: [{ required: true, message: 'Order Status is required', trigger: 'blur' }],
  customerId: [{ required: true, message: 'Customer Id is required', trigger: 'blur' }],
  customerName: [{ required: true, message: 'Customer Name is required', trigger: 'blur' }],
  customerRemark: [{ required: true, message: 'Customer Remark is required', trigger: 'blur' }],
  fromEmail: [{ required: false, message: 'From Email is required', trigger: 'blur' }],
  fromMobile: [{ required: false, message: 'From Mobile is required', trigger: 'blur' }],
  fromFamilyName: [{ required: false, message: 'From Family Name is required', trigger: 'blur' }],
  fromFirstName: [{ required: true, message: 'From First Name is required', trigger: 'blur' }],
  fromAddress1: [{ required: true, message: 'From Street is required', trigger: 'blur' }],
  fromRoom: [{ required: false, message: 'From Room is required', trigger: 'blur' }],
  fromCity: [{ required: true, message: 'From City is required', trigger: 'blur' }],
  fromState: [{ required: true, message: 'From State is required', trigger: 'blur' }],
  fromCountry: [{ required: true, message: 'From Country is required', trigger: 'blur' }],
  fromZip: [{ required: true, message: 'From Zip is required', trigger: 'blur' }],
  toEmail: [{ required: false, message: 'To Email is required', trigger: 'blur' }],
  toMobile: [{ required: false, message: 'To Mobile is required', trigger: 'blur' }],
  toName: [{ required: false, message: 'To Name is required', trigger: 'blur' }],
  toAddress1: [{ required: true, message: 'To Street is required', trigger: 'blur' }],
  toRoom: [{ required: false, message: 'To Room is required', trigger: 'blur' }],
  toCity: [{ required: true, message: 'To City is required', trigger: 'blur' }],
  toState: [{ required: true, message: 'To State is required', trigger: 'blur' }],
  toCountry: [{ required: true, message: 'To Country is required', trigger: 'blur' }],
  toZip: [{ required: true, message: 'To Zip is required', trigger: 'blur' }],
  fee: [{ required: true, message: 'Fee is required', trigger: 'blur' }],
  labelCodeOrigin: [{ required: true, message: 'Long Label Code is required', trigger: 'blur' }],
  labelCode: [{ required: true, message: 'Label Code is required', trigger: 'blur' }],
  labelType: [{ required: true, message: 'Label Type is required', trigger: 'change' }],
  labelUrl: [{ required: true, message: 'Label Url is required', trigger: 'blur' }],
  // weightkg: [ { required: true, message: "Weight (kg) is required", trigger: "blur", } ],
  weight: [{ required: true, message: 'Weight is required', trigger: 'blur' }],
  unit: [{ required: true, message: 'Unit is required', trigger: 'blur' }],
  packageCmLength: [{ required: true, message: 'Package Length is required', trigger: 'blur' }],
  packageCmWidth: [{ required: true, message: 'Package Width is required', trigger: 'blur' }],
  packageCmHeight: [{ required: true, message: 'Package Height is required', trigger: 'blur' }],
  //  packageCm3: [ { required: true, message: "Packge is required", trigger: "blur", } ],
  orderId: [{ required: false, message: 'Order Id is required', trigger: 'blur' }],
  sdkOrderId: [{ required: true, message: 'Publisher Order Id is required', trigger: 'blur' }],
  trackingHandleStatus: [{ required: true, message: 'Tracking Handle Status is required', trigger: 'blur' }],
  trackStatus: [{ required: true, message: 'Tracking Status is required', trigger: 'blur' }],
  trackLatest: [{ required: true, message: 'Track Latest is required', trigger: 'blur' }],
  innerRemark: [{ required: true, message: 'Inner Remark is required', trigger: 'blur' }],
  sku: [{ required: false, message: 'SKU is required', trigger: 'blur' }],
  testing: [{ required: true, message: 'Testing is required', trigger: 'blur' }],
  refundAmount: [{ required: true, message: 'Refund Amount is required', trigger: 'blur' }],
  refundRatio: [{ required: true, message: 'Refund Ratio is required', trigger: 'blur' }],
  refundReason: [{ required: true, message: 'Refund Reason is required', trigger: 'blur' }],
  serviceProvider: [{ required: true, message: 'Service Provider is required', trigger: 'blur' }],
  serviceType: [{ required: true, message: 'Service Type is required', trigger: 'blur' }],
})


/**
 * orderCreate实体
 * 只是一个类型说明
 */
export interface orderCreate {
  sellerOrderCode:string,      // 卖家订单流水号
  warehouseCode:string,
  shippingProductCode:string,
  toEmail?:string,           // 收货email，可选
  toMobile?:string,
  toName:string,
  toAddress1:string,
  toAddress2?:string,
  toRoom?:string,
  toCity:string,
  toState:string,
  toZip:string,
  details:SellerOrderDetailRequestVo[]    // 订单明细
  sellerOrderPackageCode:string
  shippingType:string
}

export interface SellerOrderDetailRequestVo {
  spuCode:string,      // spu编码
  skuCode:string,      // sku编码 
  count:number        // 数量
}

export const createOrderRules = reactive<FormRules>({
  "sellerOrderCode": [ { required: true, message: "客户订单号 必填", trigger: "blur", } ],
  "warehouseCode": [ { required: true, message: "仓库 必选", trigger: "change", } ],
  "shippingProductCode": [ { required: true, message: "运输方式 必选", trigger: "change", } ],
  "toName": [ { required: true, message: "收件人姓名 必填", trigger: "blur", },{ required: true, validator: enName, trigger: 'blur' } ],
  "toMobile": [{required: true, message: "收件人联系方式 必填", trigger: "blur",}],
  // "toCountry": [{required: true, message: "国家 必填", trigger: "blur",}],
  "toState": [ { required: true, message: "州 必填", trigger: "blur", } ],
  "toCity": [ { required: true, message: "城市 必填", trigger: "blur", } ],
  "toZip": [ { required: true, message: "邮编 必填", trigger: "blur", },{ required: true, validator: zipCheck, trigger: 'blur' } ],
  "details": [ { required: true, message: "订单明细 必填", trigger: "change", } ],
  "toAddress1": [ 
    { required: true, message: "详细地址1 必填", trigger: "blur", },
    { required: true, validator: enAddress, trigger: 'blur' },
    {
      max: 55,
      message: '长度不能超过55个字符',
      trigger: 'blur'
    }
  ],
  "toAddress2": [ 
    {validator: enAddress, trigger: 'blur' },
    {
      max: 35,
      message: '长度不能超过35个字符',
      trigger: 'blur'
    }
  ],
})