package com.happy.action;

import com.happy.Model.BookingComment;
import com.happy.Until.Func;
import com.happy.Until.ResUtil;
import com.happy.dto.OrderRateDto;
import com.happy.service.BookingCommentService;
import com.opensymphony.xwork2.ActionSupport;
import com.alibaba.fastjson.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.web.bind.annotation.RequestBody;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 评价
 */

public class AppBookingCommentAction extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request;

    public HttpServletResponse response;

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }


    @Resource
    public BookingCommentService bookingCommentService;


    //    评论订单id
    public String bookingId;

    //    评论民宿id
    public String hotelId;

    //    评论房型id
    public String houseId;

    //    内容
    public String content;

    //    总评分
    public Double score;

    //    卫生评分
    public Double scoreWs;

    //    服务评分
    public Double scoreFw;

    //    设施评分
    public Double scoreSs;

    //    位置评分
    public Double scoreWz;

    //    创建人
    public Integer createId;

    public String createUsername;

    //    创建时间
    public String createDate;

    //    修改时间
    public String modifyDate;

    public List<String> pictureList;

    public List<String> getPictureList() {
        return pictureList;
    }

    public void setPictureList(List<String> pictureList) {
        this.pictureList = pictureList;
    }

    public String getBookingId() {
        return bookingId;
    }

    public void setBookingId(String bookingId) {
        this.bookingId = bookingId;
    }

    public String getHotelId() {
        return hotelId;
    }

    public void setHotelId(String hotelId) {
        this.hotelId = hotelId;
    }

    public String getHouseId() {
        return houseId;
    }

    public void setHouseId(String houseId) {
        this.houseId = houseId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public Double getScoreWs() {
        return scoreWs;
    }

    public void setScoreWs(Double scoreWs) {
        this.scoreWs = scoreWs;
    }

    public Double getScoreFw() {
        return scoreFw;
    }

    public void setScoreFw(Double scoreFw) {
        this.scoreFw = scoreFw;
    }

    public Double getScoreSs() {
        return scoreSs;
    }

    public void setScoreSs(Double scoreSs) {
        this.scoreSs = scoreSs;
    }

    public Double getScoreWz() {
        return scoreWz;
    }

    public void setScoreWz(Double scoreWz) {
        this.scoreWz = scoreWz;
    }

    public Integer getCreateId() {
        return createId;
    }

    public void setCreateId(Integer createId) {
        this.createId = createId;
    }

    public String getCreateUsername() {
        return createUsername;
    }

    public void setCreateUsername(String createUsername) {
        this.createUsername = createUsername;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(String modifyDate) {
        this.modifyDate = modifyDate;
    }

    /**
     * 添加评论
     */
    public JSONObject orderRate() {
        JSONObject jsonObject = new JSONObject();
        if (score == null || score < 0 || scoreFw == null || scoreFw < 0 || scoreSs == null || scoreSs < 0 || scoreWs == null || scoreWs < 0 || scoreWz == null || scoreWz < 0 || bookingId == null || hotelId == null || houseId == null) {
            jsonObject.put("code", 400);
            jsonObject.put("message", "未传入orderRateDto数据---orderRate");
            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
            return null;
        }

        BookingComment bookingComment = BookingComment.builder().bookingId(bookingId)
                .hotelId(hotelId).houseId(houseId).content(content)
                .score(score).scoreWs(scoreWs).scoreFw(scoreFw)
                .scoreSs(scoreSs).scoreWz(scoreWz).createId(createId)
                .createUsername(createUsername).createDate(createDate)
                .modifyDate(modifyDate).build();


        int a = bookingCommentService.orderRate(bookingComment,pictureList);


        if (a>0) {
            jsonObject.put("code", 200);
            jsonObject.put("message", "添加成功");
            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
            return null;
        }
        jsonObject.put("message", "未知异常");
        jsonObject.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
        return null;
    }


    /**
     * 评价列表
     *
     * @return
     */
    public JSONObject evaluateList() {
        JSONObject jsonObject = new JSONObject();
        if (Func.checkNull(hotelId)) {
            jsonObject.put("code", 400);
            jsonObject.put("message", "未传入hotel_id数据---evaluateList");
            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
            return null;
        }


        return null;

    }


}
