export default class Selection {

    constructor() {
        this.setNulls();
    }

    setNulls() {
        this.protein = null;
        this.from = null;
        this.to = null;
        return this;
    }

    contains(protein, acid) {
        if (this.protein.name != protein.name) {
            return false;
        }
        if (this.to == null) {
            return acid.pdb_number == this.from.pdb_number
        }
        return this.from.pdb_number <= acid.pdb_number && acid.pdb_number <= this.to.pdb_number;
    }

    select(protein, acid) {
        //we selected from a different protein, or
        //we are canceling previous selection
        if ((this.protein != null && this.protein.name != protein.name) || this.to != null) {
            this.setNulls();
        }

        //nothing selected yet
        if (this.from == null) {
            this.protein = protein;
            this.from = acid;
            return false;
        }

        this.to = acid;

        //if in bad order, flip
        if (this.from.pdb_number > this.to.pdb_number) {
            [this.from, this.to] = [this.to, this.from]
        }
        return true;
    }

    isSelected() {
        return this.from && this.to;
    }


}
