import type { MemberFilterState, OptionItem } from '../../types';

import type {
  MemberDaySettingDto,
  MemberListStatsDto,
  MemberTierBenefitsDto,
  MemberTierRuleDto,
} from '#/api/member';

/** 会员管理查看权限。 */
export const MEMBER_VIEW_PERMISSION = 'tenant:member:view';

/** 会员管理编辑权限。 */
export const MEMBER_MANAGE_PERMISSION = 'tenant:member:manage';

/** 等级图标选项。 */
export const MEMBER_TIER_ICON_OPTIONS: OptionItem[] = [
  { label: '默认', value: 'user' },
  { label: '奖章', value: 'award' },
  { label: '奖杯', value: 'trophy' },
  { label: '钻石', value: 'gem' },
  { label: '皇冠', value: 'crown' },
  { label: '星星', value: 'star' },
];

/** 等级颜色选项。 */
export const MEMBER_TIER_COLOR_OPTIONS = [
  '#999999',
  '#1890ff',
  '#fa8c16',
  '#722ed1',
  '#eb2f96',
  '#f5222d',
];

/** 升级规则选项。 */
export const MEMBER_TIER_RULE_OPTIONS: OptionItem[] = [
  { label: '按累计消费金额', value: 'amount' },
  { label: '按消费次数', value: 'count' },
  { label: '同时满足', value: 'both' },
];

/** 默认筛选项。 */
export function createDefaultFilters(): MemberFilterState {
  return {
    keyword: '',
    tierId: '',
  };
}

/** 默认统计。 */
export const DEFAULT_MEMBER_STATS: MemberListStatsDto = {
  totalMembers: 0,
  monthlyNewMembers: 0,
  activeMembers: 0,
  dormantMembers: 0,
};

/** 默认会员日配置。 */
export const DEFAULT_MEMBER_DAY_SETTING: MemberDaySettingDto = {
  isEnabled: true,
  weekday: 2,
  extraDiscountRate: 9,
};

/** 默认等级规则。 */
export const DEFAULT_MEMBER_TIER_RULE: MemberTierRuleDto = {
  upgradeRuleType: 'amount',
  upgradeAmountThreshold: 500,
  upgradeOrderCountThreshold: undefined,
  downgradeWindowDays: 90,
};

/** 默认等级权益。 */
export const DEFAULT_MEMBER_TIER_BENEFITS: MemberTierBenefitsDto = {
  discount: {
    enabled: false,
    discountRate: 9.5,
  },
  pointMultiplier: {
    enabled: false,
    multiplier: 1.5,
  },
  birthday: {
    enabled: false,
    doublePointsEnabled: false,
    couponTemplateIds: [],
  },
  monthlyCoupon: {
    enabled: false,
    grantDay: 1,
    couponTemplateIds: [],
  },
  freeDelivery: {
    enabled: false,
    monthlyFreeTimes: 0,
  },
  priorityDeliveryEnabled: false,
  exclusiveServiceEnabled: false,
};
