
import {Service} from './Service'
import {LoginDto} from '@/types/Dto'
export class UserService extends Service {
    router = {
        sendCode:{ path:'/verificationCode/send/sms', dataType:'application/x-www-form-urlencoded'},
        login:{ path:'/user/login'},
        isRegisterd:{ path:'/user/isRegister', dataType:'application/x-www-form-urlencoded'},
        isPwdSet:{ path:'/user/isSetPassword', dataType:'application/x-www-form-urlencoded'},
    }
    constructor(){
        super()
    }

    /**
     * 获取验证码
     * @param phone 
     * @param codeType  短信模板, 1:登录短信 2:修改密码 3:修改手机号	
     */
    async getVerificationCode(telephone:string,codetype:string){
        return await this.service.post(this.router.sendCode.path,{},{
             headers:{"Content-Type": this.router.sendCode.dataType},
             params:{"telephone":telephone, "codetype":codetype}
         })
    }

    /**
     * 登录，没有账号则注册
     * @param data 
     * @returns 
     */
    async loginAndSign(data:LoginDto):Promise<{Authorization: string, user: object}>{
        return await this.service.post(this.router.login.path,data)
    }

    /**
     * 查看是否有该用户
     * @param account 手机号或者邮箱
     * @returns 
     */
    async isRegisterd(account:string){
        return await this.service.get(this.router.isRegisterd.path+'/'+account)
    }
    /**
     * @description 查看用户是否设置了密码
     * @param account 手机号或者邮箱
     * @returns 
     */
    async isPwdSet(account:string){
        return await this.service.get(`${this.router.isPwdSet.path}/${account}`)
    }


}


