package com.owrawww.service;

import com.owrawww.domain.Inquiry;
import com.owrawww.domain.mapper.InquiryMapper;
import com.owrawww.util.AesUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class InquiryService {

    private final InquiryMapper inquiryMapper;
    private final AesUtil aesUtil;

    public boolean submit(Inquiry inquiry) {
        Inquiry savedInquiry = new Inquiry();
            savedInquiry.setCode("1");
            savedInquiry.setTitle(inquiry.getTitle());
            savedInquiry.setComment(inquiry.getContent());
            savedInquiry.setName(inquiry.getName());
            savedInquiry.setTel(aesUtil.encrypt(inquiry.getTel()));
            savedInquiry.setTelHash(aesUtil.hash(inquiry.getTel()));
            savedInquiry.setEmail(aesUtil.encrypt(inquiry.getEmail()));
            savedInquiry.setEmailHash(aesUtil.hash(inquiry.getEmail()));
            savedInquiry.setTopCode(2);
            savedInquiry.setLeftCode(1);
            savedInquiry.setSubGubun(1);
            savedInquiry.setDepth(1);
            savedInquiry.setSolutionGubun(inquiry.getSolutionGubun());

        return inquiryMapper.insert(savedInquiry) > 0;
    }
}
