propel:
  _attributes:                { package: plugins.stPaymentPlugin.lib.model }

  payment_subscription:
    _attributes:              { phpName: PaymentSubscription, allowPkInsert: true }
    subid:                    { type: integer, size:  11, required: true, primaryKey: true, autoIncrement: true }
    name:                     { type: varchar, size: 255, required: true }
    status:                   { type: integer, size:  11, required: true, default: 0 }     # 0=Inactive, 1=Active, 2=Deleted
    timeframe_choice:         { type: integer, size:  11, required: true, default: 0 }     # 0=days, 1=weeks, 2=months, 3=years
    timeframe_value:          { type: integer, size:  11, required: true, default: 30 }    # Abo timeframe
    portal:                   { type: boolean, size:   1, required: true, default: false } # Valid for all portal contents
    chid:                     { type: integer, size:  11, required: false, default: null } # Valid for specified channel
    ends_automatically:       { type: boolean, size:   1, required: true, default: true }  # Cancel subscription at end of timeframe
    price:                    { type: double,  size:  12, scale: 2, required: true, default: 0.00 }
    created_at:               { type: timestamp, required: true }
    updated_at:               { type: timestamp, required: true }
    _foreignKeys:
      ps_fk_chid:             { foreignTable: channel, references: [ {local: chid, foreign: chid} ] }
    _indexes:
      ps_i_chid:              [chid]

  payment_ordered_subscription:
    _attributes:              { phpName: PaymentOrderedSubscription, allowPkInsert: true }
    osid:                     { type: integer, size:  11, required: true, primaryKey: true, autoIncrement: true }
    subid:                    { type: integer, size:  11, required: true }                 # Foreign key to subscription table
    uid:                      { type: integer, size:  11, required: true }                 # Foreign key to user table
    portal:                   { type: boolean, size:   1, required: true, default: false } # Valid for all portal contents
    chid:                     { type: integer, size:  11, required: false, default: null } # Valid for specified channel
    ends_automatically:       { type: boolean, size:   1, required: true, default: true }  # Cancel subscription at end of timeframe
    status:                   { type: integer, size:  11, required: true, default: 0 }     # 0=Active, 1=Expired, 2=Cancelled, 3=Deleted
    provider_name:            { type: varchar, size: 255, required: true }                 # Name of the payment provider
    provider_transaction_id:  { type: varchar, size: 255, required: false }                # Subscription transaction id
    created_at:               { type: timestamp, required: true }
    updated_at:               { type: timestamp, required: true }
    expired_at:               { type: timestamp, required: true }
    _foreignKeys:
      pos_fk_subid:           { foreignTable: payment_subscription, references: [ {local: subid, foreign: subid} ] }
      pos_fk_uid:             { foreignTable: user, references: [ {local: uid, foreign: uid} ] }
      pos_fk_chid:            { foreignTable: channel, references: [ {local: chid, foreign: chid} ] }
    _indexes:
      pos_i_subid:            [subid]
      pos_i_uid:              [uid]
      pos_i_chid:             [chid]

  payment_producer:
    _attributes:              { phpName: PaymentProducer, allowPkInsert: true }
    proid:                    { type: integer, size:  11, required: true, primaryKey: true, autoIncrement: true }
    uid:                      { type: integer, size:  11, required: true }                 # Foreign key to user table
    share_credits:            { type: double,  size:  12, scale: 2, required: true, default: 0.0 }
    share_subscription:       { type: varchar, size: 255, required: true, default: '0' }
    share_individual_sale:    { type: varchar, size: 255, required: true, default: '0' }
    status:                   { type: integer, size:  11, required: true, default: 0 }     # 0=Active, 1=Deleted
    created_at:               { type: timestamp, required: true }
    updated_at:               { type: timestamp, required: true }
    _foreignKeys:
      pp_fk_uid:              { foreignTable: user, references: [ {local: uid, foreign: uid} ] }
    _indexes:
      pp_i_uid:               [uid]

  payment_accounting:
    _attributes:              { phpName: PaymentAccounting, allowPkInsert: true }
    accid:                    { type: integer, size:  11, required: true, primaryKey: true, autoIncrement: true }
    osid:                     { type: integer, size:  11, required: false, default: null }
    mid:                      { type: integer, size:  11, required: false, default: null }
    chid:                     { type: integer, size:  11, required: false, default: null }
    pay_mode:                 { type: boolean, size:   1, required: true, default: false } # 0=Payment, 1=Subscription
    pay_option:               { type: integer, size:  11, required: true, default: 0 }     # 0=Media, 1=Channel, 2=Portal
    uid:                      { type: integer, size:  11, required: true }
    producer_uid:             { type: integer, size:  11, required: true, default: 0 }
    credits_paid:             { type: double,  size:  12, scale: 2, required: true, default: 0.00 }
    created_at:               { type: timestamp, required: true }
    updated_at:               { type: timestamp, required: true }
    expired_at:               { type: timestamp, required: true }
    _foreignKeys:
      pa_fk_uid:              { foreignTable: user, references: [ {local: uid, foreign: uid} ] }
      pa_fk_mid:              { foreignTable: media, references: [ {local: mid, foreign: mid} ] }
      pa_fk_chid:             { foreignTable: channel, references: [ {local: chid, foreign: chid} ] }
      pa_fk_osid:             { foreignTable: payment_ordered_subscription, references: [ {local: osid, foreign: osid} ] }
    _indexes:
      pa_i_uid:               [uid]
      pa_i_mid:               [mid]
      pa_i_chid:              [chid]
      pa_i_osid:              [osid]

  payment_transaction_accounting:
    _attributes:              { phpName: PaymentTransactionAccounting, allowPkInsert: true }
    taid:                     { type: integer, size:  11, required: true, primaryKey: true, autoIncrement: true }
    accid:                    { type: integer, size:  11, required: false, default: null }
    uid:                      { type: integer, size:  11, required: true }
    username:                 { type: varchar, size: 255, required: true }
    inbound:                  { type: boolean, size:   1, required: true, default: true }
    amount:                   { type: double,  size:  12, scale: 2, required: true, default: 0.00 }
    comment:                  { type: varchar, size: 255, required: true }
    payment_link:             { type: varchar, size: 255, required: false }
    created_at:               { type: timestamp, required: true }
    _foreignKeys:
      pta_fk_uid:             { foreignTable: user, references: [ {local: uid, foreign: uid} ] }
      pta_fk_accid:           { foreignTable: payment_accounting, references: [ {local: accid, foreign: accid} ] }
    _indexes:
      pta_i_uid:              [uid]
      pta_i_accid:            [accid]

  payment_user:
    _attributes:              { phpName: PaymentUser, allowPkInsert: true }
    pusid:                    { type: integer, size:  11, required: true, primaryKey: true, autoIncrement: true }
    uid:                      { type: integer, size:  11, required: true }
    credits:                  { type: double,  size:  12, scale: 2, required: true, default: 0.00 } # Payment credit account
    created_at:               { type: timestamp, required: true }
    updated_at:               { type: timestamp, required: true }
    _foreignKeys:
      pu_fk_uid:              { foreignTable: user, references: [ {local: uid, foreign: uid} ] }
    _indexes:
      pu_i_uid:               [uid]
