/*
 * Copyright (c) 2012 The 99 Software Foundation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.nnsoft.be3.model.nested;

import org.nnsoft.be3.annotations.RDFClassType;
import org.nnsoft.be3.annotations.RDFIdentifier;
import org.nnsoft.be3.annotations.RDFProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Matteo Moci ( matteo.moci (at) gmail.com )
 */

@RDFClassType(type = "http://collective.com/SimpleBook")
public class SimpleBook {

    private int id;
    private Author mainAuthor;
    private List<Author> authors = new ArrayList<Author>();

    public SimpleBook() {}

    @RDFIdentifier
    public int getId() {
        return this.id;
    }

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

    @RDFProperty (properties = {"http://collective.com/SimpleBook#mainAuthor"})
    public Author getMainAuthor() {
        return mainAuthor;
    }

    public void setMainAuthor(Author mainAuthor) {
        this.mainAuthor = mainAuthor;
    }

    public SimpleBook(int id) {
        this.id = id;
    }

    @RDFProperty(properties = {"http://collective.com/SimpleBook#author"})
    public List<Author> getAuthors() {
        return authors;
    }

    public void setAuthors(List<Author> authors) {
        this.authors = authors;
    }

    public void addAuthor(Author author) {
        this.authors.add(author);
    }

    public static class SimpleBookBuilder {

        private SimpleBook bookToBuild = new SimpleBook();

        public static SimpleBookBuilder simpleBook() {
            return new SimpleBookBuilder();
        }

        public SimpleBookBuilder withId(int id) {
            bookToBuild.setId(id);
            return this;
        }

        public SimpleBookBuilder withMainAuthor(Author author) {
            bookToBuild.setMainAuthor(author);
            return this;
        }

        public SimpleBookBuilder addAuthor(Author author) {
            bookToBuild.addAuthor(author);
            return this;
        }

        public SimpleBook build() {
            validate();
            return bookToBuild;
        }

        private void validate() {
            //do some validations
        }
    }
}
