package com.elderbyte.vidada.domain.blobstore;

import com.elderbyte.common.ArgumentNullException;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Entity
public class Blobstore {


    /***************************************************************************
     *                                                                         *
     * Fields                                                                  *
     *                                                                         *
     **************************************************************************/

    @Id
    @NotNull
    @Size(max = 50)
    @Pattern(regexp = "^[a-z0-9\\-]+$")
    @Column(length = 50)
    private String name;

    @NotNull
    @Size(max = 1000)
    @Column(length = 1000)
    private String connectionString;

    @Size(max = 100)
    @Column(length = 100)
    private String account;

    @Size(max = 100)
    @Column(length = 100)
    private String key;

    /***************************************************************************
     *                                                                         *
     * Constructors                                                            *
     *                                                                         *
     **************************************************************************/

    /**
     * ORM constructor
     */
    protected Blobstore(){ }

    public Blobstore(String name, String connectionString){
        this(name, connectionString, null ,null);
    }

    public Blobstore(String name, String connectionString, String account, String key){

        if(name == null) throw new ArgumentNullException("name");
        this.name = name.toLowerCase();

        setConnectionString(connectionString);
        setAccount(account);
        setKey(key);
    }

    /***************************************************************************
     *                                                                         *
     * Properties                                                              *
     *                                                                         *
     **************************************************************************/

    public String getName() {
        return name;
    }

    public String getConnectionString() {
        return connectionString;
    }

    public void setConnectionString(String connectionString) {
        if(connectionString == null) throw new ArgumentNullException("connectionString");

        this.connectionString = connectionString;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }


    @Override
    public String toString() {
        return "Blobstore{" +
            ", name='" + name + '\'' +
            ", connectionString='" + connectionString + '\'' +
            ", account='" + account + '\'' +
            '}';
    }
}
