/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.charles7c.continew.starter.log.common.model;

import lombok.Data;
import top.charles7c.continew.starter.log.common.enums.Include;

import java.util.*;

/**
 * 响应信息
 *
 * @author Charles7c
 * @since 1.1.0
 */
@Data
public class LogResponse {

    /**
     * 状态码
     */
    private Integer status;

    /**
     * 响应头
     */
    private Map<String, List<String>> headers;

    /**
     * 响应体（JSON 字符串）
     */
    private String body;

    /**
     * 响应参数
     */
    private Map<String, Object> param;

    public LogResponse(RecordableHttpResponse response, Set<Include> includes) {
        this.status = response.getStatus();
        this.headers = (includes.contains(Include.REQUEST_HEADERS)) ? response.getHeaders() : null;
        this.body = (includes.contains(Include.REQUEST_BODY)) ? response.getBody() : null;
        this.param = (includes.contains(Include.RESPONSE_PARAM)) ? response.getParam() : null;
    }
}