package com.eactive.httpmockserver.api.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Entity
@Table(name = "MOCK_RESPONSE")
public class MockResponse {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;

    private int statusCode = 200;

    @ElementCollection
    @CollectionTable(name = "MOCK_RESPONSE_HEADERS", joinColumns = @JoinColumn(name = "RESPONSE_ID"))
    @MapKeyColumn(name = "HEADER_KEY")
    @Column(name = "HEADER_VALUE")
    private Map<String, String> headers = new HashMap<>();

    @Lob
    private String body;

    private long delay = 0;  //millisecond

    @Column(name = "DEFAULT_RESPONSE", nullable = false, columnDefinition = "boolean default false")
    private boolean defaultResponse = false;

    @ManyToOne
    @JoinColumn(name = "ROUTE_ID", nullable = false)
    private MockRoute route;

    @OneToMany(mappedBy = "mockResponse", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<MockCondition> conditions  = new ArrayList<>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public long getDelay() {
        return delay;
    }

    public void setDelay(long delay) {
        this.delay = delay;
    }

    public MockRoute getRoute() {
        return route;
    }

    public void setRoute(MockRoute route) {
        this.route = route;
    }

    public List<MockCondition> getConditions() {
        return conditions;
    }

    public void setConditions(List<MockCondition> conditions) {
        this.conditions = conditions;
    }

    public boolean isDefaultResponse() {
        return defaultResponse;
    }

    public void setDefaultResponse(boolean defaultResponse) {
        this.defaultResponse = defaultResponse;
    }
}
