import type {
  MarketingNewCustomerCouponScene,
  MarketingNewCustomerCouponType,
  MarketingNewCustomerGiftType,
  MarketingNewCustomerInviteOrderStatus,
  MarketingNewCustomerInviteRewardStatus,
  MarketingNewCustomerShareChannel,
} from '#/api/marketing';
import type {
  NewCustomerCouponDrawerForm,
  NewCustomerInviteRecordPager,
  NewCustomerPageForm,
  NewCustomerStatsViewModel,
} from '#/views/marketing/new-customer/types';

/**
 * 文件职责：新客有礼页面常量与默认值。
 */

/** 查看权限码。 */
export const NEW_CUSTOMER_VIEW_PERMISSION =
  'tenant:marketing:new-customer:view';

/** 管理权限码。 */
export const NEW_CUSTOMER_MANAGE_PERMISSION =
  'tenant:marketing:new-customer:manage';

/** 礼包类型选项。 */
export const NEW_CUSTOMER_GIFT_TYPE_OPTIONS: Array<{
  label: string;
  value: MarketingNewCustomerGiftType;
}> = [
  { label: '优惠券包', value: 'coupon' },
  { label: '首单直减', value: 'direct' },
];

/** 分享渠道选项。 */
export const NEW_CUSTOMER_SHARE_CHANNEL_OPTIONS: Array<{
  label: string;
  value: MarketingNewCustomerShareChannel;
}> = [
  { label: '微信好友', value: 'wechat_friend' },
  { label: '朋友圈', value: 'moments' },
  { label: '短信', value: 'sms' },
];

/** 券类型选项。 */
export const NEW_CUSTOMER_COUPON_TYPE_OPTIONS: Array<{
  label: string;
  value: MarketingNewCustomerCouponType;
}> = [
  { label: '满减券', value: 'amount_off' },
  { label: '折扣券', value: 'discount' },
  { label: '免配送费', value: 'free_shipping' },
];

/** 券场景标题。 */
export const NEW_CUSTOMER_COUPON_SCENE_TITLE_MAP: Record<
  MarketingNewCustomerCouponScene,
  string
> = {
  welcome: '新客礼包券',
  inviter: '邀请人奖励券',
  invitee: '被邀请人奖励券',
};

/** 邀请记录订单状态文案。 */
export const NEW_CUSTOMER_ORDER_STATUS_TEXT_MAP: Record<
  MarketingNewCustomerInviteOrderStatus,
  string
> = {
  pending_order: '待下单',
  ordered: '已下单',
};

/** 邀请记录奖励状态文案。 */
export const NEW_CUSTOMER_REWARD_STATUS_TEXT_MAP: Record<
  MarketingNewCustomerInviteRewardStatus,
  string
> = {
  pending: '待触发',
  issued: '已发放',
};

/** 创建默认页面表单。 */
export function createDefaultNewCustomerPageForm(): NewCustomerPageForm {
  return {
    giftEnabled: true,
    giftType: 'coupon',
    directReduceAmount: 10,
    directMinimumSpend: 30,
    inviteEnabled: true,
    shareChannels: ['wechat_friend', 'moments'],
    welcomeCoupons: [],
    inviterCoupons: [],
    inviteeCoupons: [],
  };
}

/** 创建默认统计。 */
export function createDefaultNewCustomerStats(): NewCustomerStatsViewModel {
  return {
    monthlyNewCustomers: 0,
    monthlyGrowthCount: 0,
    monthlyGrowthRatePercent: 0,
    giftClaimRate: 0,
    giftClaimedCount: 0,
    firstOrderConversionRate: 0,
    firstOrderedCount: 0,
  };
}

/** 创建默认邀请记录分页。 */
export function createDefaultNewCustomerInvitePager(): NewCustomerInviteRecordPager {
  return {
    items: [],
    page: 1,
    pageSize: 10,
    totalCount: 0,
  };
}

/** 创建默认券抽屉表单。 */
export function createDefaultNewCustomerCouponDrawerForm(): NewCustomerCouponDrawerForm {
  return {
    couponType: 'amount_off',
    value: null,
    minimumSpend: null,
    validDays: 7,
  };
}
