import { post, request } from '@/utils/request';

export interface SellerRegisterParams {
  phone: string;
  code: string;
  contactName: string;
  email?: string;
  password?: string;
}

export interface SellerLoginParams {
  phone: string;
  code?: string;
  password?: string;
}

export interface SellerLoginResult {
  accessToken: string;
  refreshToken: string;
  sellerInfo: {
    id: number;
    phone: string;
    contactName: string;
    email?: string;
    status: string;
    merchantId?: number;
    merchantStatus?: string;
  };
}

// 发送商家验证码
export function sellerSendCode(phone: string) {
  return post('/api/merchant/auth/send-code', { phone });
}

// 商家注册（验证码）
export function sellerRegister(data: SellerRegisterParams) {
  return request<SellerLoginResult>({ url: '/api/merchant/auth/register', method: 'POST', data, useSellerToken: true, skipAuthRedirect: true });
}

// 商家登录（验证码或密码）
export function sellerLogin(data: SellerLoginParams) {
  return request<SellerLoginResult>({ url: '/api/merchant/auth/login', method: 'POST', data, useSellerToken: true, skipAuthRedirect: true });
}

// 刷新商家令牌
export function sellerRefreshToken(refreshToken: string) {
  return post<SellerLoginResult>('/api/merchant/auth/refresh', { refreshToken });
}

// 获取商家信息（需要商家token）
export function getSellerProfile() {
  return request({ url: '/api/merchant/auth/profile', method: 'GET', useSellerToken: true });
}
