import type {
  MarketingNewCustomerCouponRuleDto,
  MarketingNewCustomerCouponScene,
  MarketingNewCustomerCouponType,
  MarketingNewCustomerGiftType,
  MarketingNewCustomerInviteRecordDto,
  MarketingNewCustomerShareChannel,
  MarketingNewCustomerStatsDto,
} from '#/api/marketing';

/**
 * 文件职责：新客有礼页面类型定义。
 */

/** 页面可编辑优惠券项。 */
export interface NewCustomerCouponFormItem {
  couponType: MarketingNewCustomerCouponType;
  id: string;
  minimumSpend: null | number;
  scene: MarketingNewCustomerCouponScene;
  sortOrder: number;
  validDays: number;
  value: null | number;
}

/** 页面可编辑表单。 */
export interface NewCustomerPageForm {
  directMinimumSpend: null | number;
  directReduceAmount: null | number;
  giftEnabled: boolean;
  giftType: MarketingNewCustomerGiftType;
  inviteEnabled: boolean;
  inviteeCoupons: NewCustomerCouponFormItem[];
  inviterCoupons: NewCustomerCouponFormItem[];
  shareChannels: MarketingNewCustomerShareChannel[];
  welcomeCoupons: NewCustomerCouponFormItem[];
}

/** 券抽屉表单。 */
export interface NewCustomerCouponDrawerForm {
  couponType: MarketingNewCustomerCouponType;
  minimumSpend: null | number;
  validDays: number;
  value: null | number;
}

/** 邀请记录分页模型。 */
export interface NewCustomerInviteRecordPager {
  items: MarketingNewCustomerInviteRecordDto[];
  page: number;
  pageSize: number;
  totalCount: number;
}

/** 统计视图模型。 */
export type NewCustomerStatsViewModel = MarketingNewCustomerStatsDto;

/** 邀请记录视图模型。 */
export type NewCustomerInviteRecordViewModel =
  MarketingNewCustomerInviteRecordDto;

/** 映射为页面可编辑券项。 */
export function toCouponFormItem(
  source: MarketingNewCustomerCouponRuleDto,
): NewCustomerCouponFormItem {
  return {
    id: source.id,
    scene: source.scene,
    couponType: source.couponType,
    value: source.value,
    minimumSpend: source.minimumSpend,
    validDays: source.validDays,
    sortOrder: source.sortOrder,
  };
}
