package com.sikey.wa04.api.user.client.rest;

import com.sikey.wa04.business.application.service.user.ContactsService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.contact.CreateContactRequest;
import com.sikey.wa04.business.infrastructure.dto.request.contact.DeleteContactRequest;
import com.sikey.wa04.business.infrastructure.dto.request.contact.GetContactRequest;
import com.sikey.wa04.business.infrastructure.dto.request.contact.UpdateContactRequest;
import com.sikey.wa04.business.infrastructure.dto.response.contact.GetContactResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import com.sikey.wa04.common.interceptor.Authenticated;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * ContactController
 *
 * @author luoyangwei
 * @date 2024年10月10日16:12:38
 */
@RestController
@RequestMapping(ProjectContextConstant.USER_CONTEXT_URL + "/user/child/contacts")
public class ContactController extends BaseController {

    @Resource
    private ContactsService contactsService;

    /**
     * 创建联系人
     *
     * @param request CreateContactRequest
     * @return ResponseEntity<Object>
     */
    @Authenticated
    @PostMapping("/create")
    public void create(@Valid @RequestBody CreateContactRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        contactsService.createMember(request,genericManufacturerHeader);
    }

    /**
     * 删除联系人
     *
     * @param request DeleteContactRequest
     * @return ResponseEntity<Object>
     */
    @Authenticated
    @GetMapping("/delete")
    public void delete(@Valid DeleteContactRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        contactsService.deleteMember(request,genericManufacturerHeader);
    }

    /**
     * 获取联系人
     *
     * @param request GetContactRequest
     * @return ResponseEntity<GetContactResponse>
     */
    @Authenticated
    @GetMapping("/get")
    public GetContactResponse get(@Valid GetContactRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return contactsService.get(request,genericManufacturerHeader,false);
    }

    /**
     * 更新联系人
     *
     * @param request UpdateContactRequest
     * @return ResponseEntity<Object>
     */
    @Authenticated
    @PostMapping("/update")
    public void update(@Valid @RequestBody UpdateContactRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        contactsService.updateMember(request,genericManufacturerHeader);
    }

}
