# [ USER GROUP ]
UserGroup:
  tableName:             s_user_group
  actAs:                 { Timestampable: ~ }
  columns:
    id:                  { type: integer(2), primary: true, autoincrement: true }
    name:                { type: varchar(255) }
    description:         { type: varchar(255) }

# [ USER CREDENTIAL ]
UserCredential:
  tableName:             s_user_credential
  actAs:                 { Timestampable: ~ }
  columns:
    id:                  { type: integer(5), primary: true, autoincrement: true }
    user_id:             { type: integer(5) }
    group_id:            { type: integer(2) }
  relations:
    User:                { onDelete: CASCADE, local: user_id, foreign: id }
    UserGroup:           { onDelete: CASCADE, local: group_id, foreign: id }

# [ USER ]
User:
  tableName:             s_user
  actAs:                 { Timestampable: ~ }
  columns:
    id:                  { type: integer(5), primary: true, autoincrement: true }
    username:            { type: varchar(50), notnull: true }
    email:               { type: varchar(150), notnull: true }
    sha1_password:       { type: varchar(40) }
    salt:                { type: varchar(32) }
    validate:            { type: varchar(10) }
    remember_key:        { type: varchar(50) }
    firstname:           { type: varchar(255), notnull: true }
    lastname:            { type: varchar(255) }
    last_attemp:         { type: timestamp }
    attemp_count:        { type: integer(2), default: 0 }
    lastlogin_date:      { type: timestamp }
  relations:
    Groups:              { class: UserGroup, refClass: UserCredential, local: user_id, foreign: group_id, foreignAlias: Users }

# [ WEB OPTIONS ]
WebOptions:
  tableName:             web_options
  actAs:                 { Timestampable: ~ }
  columns:
    option_id:           { type: integer(4), primary: true, autoincrement: true }
    option_name:         { type: varchar(100), notnull: true }
    option_value:        { type: varchar }

# [ WEB LANGUAGE ]
WebLanguage:
  tableName:             web_language
  actAs:                 { Timestampable: ~ }
  columns:
    code:                { type: varchar(2), primary: true }
    language:            { type: varchar(100), notnull: true }
    position:            { type: integer(4), default: 0 }
    is_active:           { type: boolean, default: true }

# [ WEB POSTS ]
WebPost:
  tableName:             web_posts
  actAs:
    Timestampable: ~
    I18n:
      fields:            [ post_content, post_title ]
  columns:
    post_id:             { type: integer(5), primary: true, autoincrement: true }
    post_author:         { type: integer(5), notnull: true }
    post_content:        { type: clob, notnull: true }
    post_title:          { type: varchar, notnull: true }
    post_status:         { type: varchar(20), default: 'publish' }
    comment_status:      { type: varchar(20), default: 'open' }
    post_name:           { type: varchar, notnull: true }
    guid:                { type: varchar, notnull: true }
    menu_order:          { type: integer(4), default: 0 }
    post_type:           { type: varchar(20), default: 'post' } # post or page
    comment_count:       { type: integer(5), default: 0 }
    is_active:           { type: boolean, default: false }

# [ WEB POSTS META ]
WebPostMeta:
  tableName:             web_postmeta
  actAs:                 { Timestampable: ~ }
  columns:
    meta_id:             { type: integer(5), primary: true, autoincrement: true }
    post_id:             { type: integer(5), notnull: true }
    meta_key:            { type: varchar(255) }
    meta_value:          { type: clob }
  relations:
    WebPost:             { onDelete: CASCADE, local: post_id, foreign: post_id, foreignAlias: WebPostMetas }

# [ WEB CATEGORY ]
WebCategory:
  tableName:             web_category
  actAs:
    Timestampable:       ~
    I18n:
      fields:            [ name ]
    NestedSet:
      hasManyRoots:      true
      rootColumnName:    parent_id
  columns:
    id:                  { type: integer(4), primary: true, autoincrement: true }
    parent_id:           { type: integer(4), default: 0 }
    name:                { type: varchar(255) }
    alias:               { type: varchar(255) }
    position:            { type: integer(4), default: 0 }
    is_hidden:           { type: boolean, default: false }
    type:                { type: varchar(50) }
  relations:
    WebPosts:            { class: WebPost, refClass: WebCategoryRelationship, local: category_id, foreign: post_id, foreignAlias: WebCategories }

# [ WEB CATEGORY RELATIONSHIP ]
WebCategoryRelationship:
  tableName:             web_category_relationship
  actAs:                 { Timestampable: ~ }
  columns:
    id:                  { type: integer(5), primary: true, autoincrement: true }
    category_id:         { type: integer(4) }
    post_id:             { type: integer(5) }
  relations:
    WebCategory:         { onDelete: CASCADE, local: category_id, foreign: id }
    WebPost:             { onDelete: CASCADE, local: post_id, foreign: post_id }

# [ WEB MENU ]
WebMenu:
  tableName:             web_menu
  actAs:
    Timestampable:       ~    
    I18n:
      fields:            [ name, title ]
  columns:
    id:                  { type: integer(4), primary: true, autoincrement: true }
    parent_id:           { type: integer(4), default: 0 }
    name:                { type: varchar(255) }
    title:               { type: varchar(255) }
    type:                { type: varchar(20) }
    url:                 { type: varchar(500) }
    is_active:           { type: boolean, default: true }
    position:            { type: integer(4), default: 0 }

# [ POLL ]
Poll:
  tableName:             web_poll
  actAs:
    Timestampable:       ~
    I18n:
        fields:          [ question ]
  columns:
    id:                  { type: integer(4), primary: true, autoincrement: true }
    question:            { type: varchar(500) }
    is_active:           { type: boolean, default: false }

# [ POLL ANSWERS ]
PollAnswer:
  tableName:             web_poll_answer
  actAs:
      I18n:
          fields:        [ answer ]
  columns:
    id:                  { type: integer(4), primary: true, autoincrement: true }
    poll_id:             { type: integer(4) }
    answer:              { type: varchar(255) }
    position:            { type: integer(4), default: 0 }
  relations:
    Poll:                { onDelete: CASCADE, local: poll_id, foreign: id, foreignAlias: Poll }

# [ POLL VOTE ]
PollVote:
  tableName:             web_poll_vote
  actAs:                 { Timestampable: ~ }
  columns:
    id:                  { type: integer(11), primary: true, autoincrement: true }
    ip:                  { type: varchar(30) }
    poll_id:             { type: integer(4) }
    answer_id:           { type: integer(4) }
  relations:
    PollAnswer:          { local: answer_id, foreign: id, type: one }
    Poll:                { onDelete: CASCADE, local: poll_id, foreign: id, foreignAlias: Poll }

# [ VISIT ]
Visit:
  tableName:             web_visit
  actAs:                 { Timestampable: ~ }
  columns:
    id:                  { type: integer(5), primary: true, autoincrement: true }
    url:                 { type: varchar(500), notnull: true }
    ip:                  { type: varchar(20), notnull: true }
