/**
 * A piece of art stored in the database.
 *
 * @author Colin Campbell
 * @author Aden Beihl
 * @author Bradley Hilkene
 * @author Alex Brown
 */
public class Art 
  extends DatabaseEntry
{

    // +--------+--------------------------------------------------
    // | Fields |
    // +--------+

    /** The field for title input. */
    protected String titlefield;
    /** The field for first name input. */
    protected String fnamefield;
    /** The field for the last name input. */
    protected String lnamefield;
    /** The field for input of the genre. */
    protected String genrefield;
    /** The field for input of the medium. */
    protected String medfield;
    /** The field for input of the size. */
    protected String sizefield;
    /** The field for input of the current bid, in cents */
    protected String currentfield;
    /** The field for input of the minimum bid, in cents */
    protected String minbidfield;
    /** The label for number of bids received. */
    protected String bidrecfield;
    /** The key of the artist who created the work. */
    protected String artist;
    /** The number of bidders on the work. */
    protected String numBidders;
    /** Is this piece slated for auction? */
    protected boolean auctionable;
    /** What is the location of the piece of art? */
    protected String location;
    
    // +--------------+--------------------------------------------
    // | Constructors |  
    // +--------------+  
    
    /**
     * Creates an new art object.
     * Pre: All field values are clear.
     * Post: A new blank art object has been created.
     */
    
    public Art() {
    }
    
    // +-----------+-----------------------------------------------
    // | Modifiers |
    // +-----------+
    
    /**
     * Get a particular field.  Simplifies the Database object.
     */
    public void setField(String fieldName, String newValue) 
      throws Exception
    {
        fieldName = fieldName.toLowerCase();
        if (fieldName.equals("title"))
            setTitle(newValue);
        else if (fieldName.equals("firstname") || fieldName.equals("first name")
                  || fieldName.equals("fname"))
            setFname(newValue);
        else if (fieldName.equals("lastname") || fieldName.equals("last name")
                  || fieldName.equals("lname"))
            setLname(newValue);
        else if (fieldName.equals("genre"))
            setGenre(newValue);
        else if (fieldName.equals("medium") || fieldName.equals("med"))
            setMed(newValue);
        else if (fieldName.equals("size"))
            setSize(newValue);
        else if (fieldName.equals("current"))
            setCurrent(newValue);
        else if (fieldName.equals("minbid") || fieldName.equals("min"))
            setMin(newValue);
        else if (fieldName.equals("bidrec") || fieldName.equals("bids"))
            setBidrec(newValue);
        else if (fieldName.equals("artist"))
            setArtist(newValue);
        else if (fieldName.equals("numbidders"))
            setNumbidders(newValue);
        else if (fieldName.equals("auctionable")) {
            // Convert from string to boolean.
            newValue = newValue.toLowerCase();
            if (newValue.equals("t") || newValue.equals("true"))
              setAuctionable(true);
            else
              setAuctionable(false);
        }
        else if (fieldName.equals("location"))
            setLocation(newValue);
        else
            super.setField(fieldName,newValue);
    } // setField(String)

    /**
     * Set the title field.
     * Pre: The title entered is valid.
     * Post: The title field has been set.
     */
    public void setTitle(String string) {
      this.titlefield = string;
      setName(titlefield + " (" + fnamefield + " " + lnamefield + ")");
    }
  
    /**
     * Set the key of the artist.
     */
    public void setArtist(String artistKey) {
      artist = artistKey;
    } // setArtist()

    /**
     * Set the ID field.
     * Pre: The ID entered is valid.
     * Post: The ID field has been set.
     */
    public void setID(String string) {
        this.setId(string);
    }
  
    /**
     * Set the First Name field.
     * Pre: The First Name entered is valid.
     * Post: The First Name field has been set.
     */
    public void setFname(String string) {
        this.fnamefield = string;
        setName(titlefield + " (" + fnamefield + " " + lnamefield + ")");
    }
  
    /**
     * Set the Last Name field.
     * Pre: The Last Name entered is valid.
     * Post: The Last Name field has been set.
     */
    public void setLname(String string) {
        this.lnamefield = string;
        setName(titlefield + " (" + fnamefield + " " + lnamefield + ")");
    }
    
    /**
     * Set the Genre field.
     * Pre: The Genre entered is valid.
     * Post: The Genre field has been set.
     */
    public void setGenre(String string) {
        this.genrefield = string;
    }
    
    /**
     * Set the Medium field.
     * Pre: The Medium entered is valid.
     * Post: The Medium field has been set.
     */
    public void setMed(String string) {
        this.medfield = string;
    }
  
    /**
     * Set the Size field.
     * Pre: The Size entered is valid.
     * Post: The Size field has been set.
     */
    public void setSize(String string) {
        this.sizefield = string;
    }
  
    /**
     * Set the Current Bid field.
     * Pre: The Current Bid entered is valid.
     * Post: The Current Bid field has been set.
     */
    public void setCurrent(String string) {
        this.currentfield = string;
    }
  
    /**
     * Set the Minimum Bid field.
     * Pre: The Minimum Bid entered is valid.
     * Post: The Minimum Bid field has been set.
     */
    public void setMin(String string) {
        this.minbidfield = string;
    }
    
    /**
     * Set the Bids Recieved field.
     * Pre: The Bids Recieved entered is valid.
     * Post: The Bids Recieved field has been set.
     */
    public void setBidrec(String string) {
        this.bidrecfield = string;
    }
    
    /**
     * Set the lcoation of the piece of art.
     */
    public void setLocation(String string) {
        this.location = string;
    }
    
    public void setNumbidders(String string) {
        this.numBidders = string;
    }
    
    public void setAuctionable(boolean state) {
        this.auctionable = state;
    }
    
    public void setKeyfield(String string) {
        setKey(string);
    }
    
    // +-----------+-----------------------------------------------
    // | Accessors |
    // +-----------+
    
    /**
     * List all the fields.  Simplifies the Database object.
     */
    public String[] listFields() {
        String[] parentFields = super.listFields();
        String[] myFields = {
            "Title",
            "Fname",
            "Lname",
            "Genre",
            "Medium",
            "Size",
            "Current",
            "MinBid",
            "BidRec",
            "Artist",
            "NumBidders",
            "Auctionable",
            "Location"
        };
        String[] result = new String[parentFields.length + myFields.length];
        for (int i = 0; i < parentFields.length; ++i) {
          result[i] = parentFields[i];
        }
        for (int i = 0; i < myFields.length; ++i) {
          result[parentFields.length+i] = myFields[i];
        }
        return result;
    } // listFields()

    /**
     * Get a particular field.  Simplifies the Database object.
     */
    public String getField(String fieldName) 
      throws Exception
    {
        fieldName = fieldName.toLowerCase();
        if (fieldName.equals("title"))
            return getTitle();
        else if (fieldName.equals("firstname") || fieldName.equals("first name")
                  || fieldName.equals("fname"))
            return getFname();
        else if (fieldName.equals("lastname") || fieldName.equals("last name")
                  || fieldName.equals("lname"))
            return getLname();
        else if (fieldName.equals("genre"))
            return getGenre();
        else if (fieldName.equals("medium") || fieldName.equals("med"))
            return getMed();
        else if (fieldName.equals("size"))
            return getSize();
        else if (fieldName.equals("current"))
            return getCurrent();
        else if (fieldName.equals("minbid") || fieldName.equals("min"))
            return getMin();
        else if (fieldName.equals("bidrec") || fieldName.equals("bids"))
            return getBidrec();
        else if (fieldName.equals("artist"))
            return getArtist();
        else if (fieldName.equals("numbidders"))
            return getNumbidders();
        else if (fieldName.equals("auctionable"))
            return "" + getAuctionable();	// Convert to string.
        else if (fieldName.equals("location"))
            return getLocation();
        else
            return super.getField(fieldName);
    } // getField(String)

    public String getTitle() {
        return this.titlefield;
    } // getTitle
  
    public String getID() {
        return this.getId();
    }
    
    public String getArtist() {
        return this.artist;
    }

    public String getFname() {
        return this.fnamefield;
    }
    
    public String getLname() {
        return this.lnamefield;
    }
  
    public String getGenre() {
        return this.genrefield;
    }
  
    public String getMed() {
        return this.medfield;
    }
    
    public String getSize() {
        return this.sizefield;
    }
    
    public String getCurrent() {
        return this.currentfield;
    }
    
    public String getMin() {
        return this.minbidfield;
    }
    
    public String getBidrec() {
        return this.bidrecfield;
    }

    public String getArtkey() {
        return this.artist;
    }

    public String getNumbidders() {
        return this.numBidders;
    }

    public boolean getAuctionable() {
        return this.auctionable;
    }
    
    public String getLocation() {
        return this.location;
    }

} // Art class



