package com.izouma.nineth.web.mobile.v1;


import com.izouma.nineth.domain.IdentityAuth;
import com.izouma.nineth.dto.PageQuery;
import com.izouma.nineth.service.IdentityAuthService;
import com.izouma.nineth.utils.SecurityUtils;
import com.izouma.nineth.web.BaseController;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/identityAuth/v1")
@AllArgsConstructor
@Slf4j
public class IdentityAuthControllerV1 extends BaseController {
    private IdentityAuthService identityAuthService;



    @PostMapping("/apply")
    public void apply(IdentityAuth identityAuth) {
        identityAuth.setUserId(SecurityUtils.getAuthenticatedUser().getId());
        identityAuthService.apply(identityAuth);
    }

    @PostMapping("/my")
    public Page<IdentityAuth> my() {
        PageQuery pageQuery = new PageQuery();
        pageQuery.setPage(0);
        pageQuery.setSize(1);
        pageQuery.getQuery().put("userId",currentUser().getId());
        pageQuery.getQuery().put("del",false);
        pageQuery.getQuery().put("status","SUCCESS");
        pageQuery.setSort("createdAt,desc");
        return identityAuthService.all(pageQuery);
    }
}

