import type {
  MarketingCouponChannel,
  MarketingCouponDisplayStatus,
  MarketingCouponStoreScopeMode,
  MarketingCouponType,
} from '#/api/marketing';
import type {
  CouponEditorForm,
  CouponFilterForm,
} from '#/views/marketing/coupon/types';

/**
 * 文件职责：优惠券页面常量定义与默认表单构造。
 */

/** 列表状态筛选项。 */
export const COUPON_STATUS_FILTER_OPTIONS: Array<{
  label: string;
  value: '' | MarketingCouponDisplayStatus;
}> = [
  { label: '全部状态', value: '' },
  { label: '进行中', value: 'ongoing' },
  { label: '未开始', value: 'upcoming' },
  { label: '已结束', value: 'ended' },
  { label: '暂停领取', value: 'disabled' },
];

/** 列表类型筛选项。 */
export const COUPON_TYPE_FILTER_OPTIONS: Array<{
  label: string;
  value: '' | MarketingCouponType;
}> = [
  { label: '全部类型', value: '' },
  { label: '满减券', value: 'amount_off' },
  { label: '折扣券', value: 'discount' },
  { label: '免配送费券', value: 'free_delivery' },
];

/** 编辑态券类型项。 */
export const COUPON_EDITOR_TYPE_OPTIONS: Array<{
  label: string;
  value: MarketingCouponType;
}> = [
  { label: '满减券', value: 'amount_off' },
  { label: '折扣券', value: 'discount' },
  { label: '免配送费券', value: 'free_delivery' },
];

/** 有效期类型项。 */
export const COUPON_VALIDITY_OPTIONS = [
  { label: '固定时间', value: 'fixed' },
  { label: '领取后N天', value: 'days' },
] as const;

/** 渠道选项。 */
export const COUPON_CHANNEL_OPTIONS: Array<{
  label: string;
  value: MarketingCouponChannel;
}> = [
  { label: '外卖', value: 'delivery' },
  { label: '自提', value: 'pickup' },
  { label: '堂食', value: 'dine_in' },
];

/** 门店范围选项。 */
export const COUPON_STORE_SCOPE_OPTIONS: Array<{
  label: string;
  value: MarketingCouponStoreScopeMode;
}> = [
  { label: '全部门店', value: 'all' },
  { label: '指定门店', value: 'stores' },
];

/** 列表状态文本。 */
export const COUPON_STATUS_TEXT_MAP: Record<
  MarketingCouponDisplayStatus,
  string
> = {
  ongoing: '进行中',
  upcoming: '未开始',
  ended: '已结束',
  disabled: '暂停领取',
};

/** 列表状态徽标样式。 */
export const COUPON_STATUS_TAG_CLASS_MAP: Record<
  MarketingCouponDisplayStatus,
  string
> = {
  ongoing: 'mcp-status-ongoing',
  upcoming: 'mcp-status-upcoming',
  ended: 'mcp-status-ended',
  disabled: 'mcp-status-disabled',
};

/** 渠道文本映射。 */
export const COUPON_CHANNEL_TEXT_MAP: Record<MarketingCouponChannel, string> = {
  delivery: '外卖',
  pickup: '自提',
  dine_in: '堂食',
};

/** 构建默认筛选表单。 */
export function createDefaultCouponFilterForm(): CouponFilterForm {
  return {
    status: '',
    couponType: '',
  };
}

/** 构建默认编辑表单。 */
export function createDefaultCouponEditorForm(): CouponEditorForm {
  return {
    id: '',
    name: '',
    couponType: 'amount_off',
    value: null,
    minimumSpend: null,
    totalQuantity: 1000,
    perUserLimit: 1,
    validityType: 'fixed',
    validDateRange: null,
    relativeValidDays: 7,
    channels: ['delivery', 'pickup', 'dine_in'],
    storeScopeMode: 'all',
    storeIds: [],
    status: 'disabled',
  };
}
