/*
 * This file is generated by jOOQ.
 */
package ru.micord.webbpm.ervu.business_metrics.db_beans.metrics.tables;


import java.math.BigDecimal;
import java.util.Collection;

import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.PlainSQL;
import org.jooq.QueryPart;
import org.jooq.SQL;
import org.jooq.Schema;
import org.jooq.Select;
import org.jooq.Stringly;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

import ru.micord.webbpm.ervu.business_metrics.db_beans.metrics.Metrics;
import ru.micord.webbpm.ervu.business_metrics.db_beans.metrics.tables.records.ViewCitizenAppealsRecord;


/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class ViewCitizenAppeals extends TableImpl<ViewCitizenAppealsRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>metrics.view_citizen_appeals</code>
     */
    public static final ViewCitizenAppeals VIEW_CITIZEN_APPEALS = new ViewCitizenAppeals();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<ViewCitizenAppealsRecord> getRecordType() {
        return ViewCitizenAppealsRecord.class;
    }

    /**
     * The column <code>metrics.view_citizen_appeals.citizen_appeals_id</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, Long> CITIZEN_APPEALS_ID = createField(DSL.name("citizen_appeals_id"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>metrics.view_citizen_appeals.count_accepted_to_consideration</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, Long> COUNT_ACCEPTED_TO_CONSIDERATION = createField(DSL.name("count_accepted_to_consideration"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>metrics.view_citizen_appeals.count_submitted_difference_accepted</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, Long> COUNT_SUBMITTED_DIFFERENCE_ACCEPTED = createField(DSL.name("count_submitted_difference_accepted"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>metrics.view_citizen_appeals.percent_accepted_to_consideration</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, BigDecimal> PERCENT_ACCEPTED_TO_CONSIDERATION = createField(DSL.name("percent_accepted_to_consideration"), SQLDataType.NUMERIC, this, "");

    /**
     * The column <code>metrics.view_citizen_appeals.percent_satisfided</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, BigDecimal> PERCENT_SATISFIDED = createField(DSL.name("percent_satisfided"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>metrics.view_citizen_appeals.percent_not_satisfided</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, BigDecimal> PERCENT_NOT_SATISFIDED = createField(DSL.name("percent_not_satisfided"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>metrics.view_citizen_appeals.percent_accepted_expired</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, BigDecimal> PERCENT_ACCEPTED_EXPIRED = createField(DSL.name("percent_accepted_expired"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>metrics.view_citizen_appeals.percent_accepted_on_time</code>.
     */
    public final TableField<ViewCitizenAppealsRecord, BigDecimal> PERCENT_ACCEPTED_ON_TIME = createField(DSL.name("percent_accepted_on_time"), SQLDataType.NUMERIC, this, "");

    private ViewCitizenAppeals(Name alias, Table<ViewCitizenAppealsRecord> aliased) {
        this(alias, aliased, (Field<?>[]) null, null);
    }

    private ViewCitizenAppeals(Name alias, Table<ViewCitizenAppealsRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_citizen_appeals" as  SELECT citizen_appeals.citizen_appeals_id,
         (((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time) AS count_accepted_to_consideration,
         (citizen_appeals.count_submitted - (((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time)) AS count_submitted_difference_accepted,
         COALESCE(round(((((((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time))::numeric * (100)::numeric) / NULLIF((citizen_appeals.count_submitted)::numeric, (0)::numeric))), (0)::numeric) AS percent_accepted_to_consideration,
         COALESCE(round((((citizen_appeals.count_satisfided)::numeric * (100)::numeric) / NULLIF(((((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time))::numeric, (0)::numeric))), (0)::numeric) AS percent_satisfided,
         COALESCE(round((((citizen_appeals.count_not_satisfided)::numeric * (100)::numeric) / NULLIF(((((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time))::numeric, (0)::numeric))), (0)::numeric) AS percent_not_satisfided,
         COALESCE(round((((citizen_appeals.count_accepted_expired)::numeric * (100)::numeric) / NULLIF(((((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time))::numeric, (0)::numeric))), (0)::numeric) AS percent_accepted_expired,
         COALESCE(round((((citizen_appeals.count_accepted_on_time)::numeric * (100)::numeric) / NULLIF(((((citizen_appeals.count_satisfided + citizen_appeals.count_not_satisfided) + citizen_appeals.count_accepted_expired) + citizen_appeals.count_accepted_on_time))::numeric, (0)::numeric))), (0)::numeric) AS percent_accepted_on_time
        FROM metrics.citizen_appeals;
        """), where);
    }

    /**
     * Create an aliased <code>metrics.view_citizen_appeals</code> table
     * reference
     */
    public ViewCitizenAppeals(String alias) {
        this(DSL.name(alias), VIEW_CITIZEN_APPEALS);
    }

    /**
     * Create an aliased <code>metrics.view_citizen_appeals</code> table
     * reference
     */
    public ViewCitizenAppeals(Name alias) {
        this(alias, VIEW_CITIZEN_APPEALS);
    }

    /**
     * Create a <code>metrics.view_citizen_appeals</code> table reference
     */
    public ViewCitizenAppeals() {
        this(DSL.name("view_citizen_appeals"), null);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : Metrics.METRICS;
    }

    @Override
    public ViewCitizenAppeals as(String alias) {
        return new ViewCitizenAppeals(DSL.name(alias), this);
    }

    @Override
    public ViewCitizenAppeals as(Name alias) {
        return new ViewCitizenAppeals(alias, this);
    }

    @Override
    public ViewCitizenAppeals as(Table<?> alias) {
        return new ViewCitizenAppeals(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public ViewCitizenAppeals rename(String name) {
        return new ViewCitizenAppeals(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public ViewCitizenAppeals rename(Name name) {
        return new ViewCitizenAppeals(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public ViewCitizenAppeals rename(Table<?> name) {
        return new ViewCitizenAppeals(name.getQualifiedName(), null);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewCitizenAppeals where(Condition condition) {
        return new ViewCitizenAppeals(getQualifiedName(), aliased() ? this : null, null, condition);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewCitizenAppeals where(Collection<? extends Condition> conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewCitizenAppeals where(Condition... conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewCitizenAppeals where(Field<Boolean> condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewCitizenAppeals where(SQL condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewCitizenAppeals where(@Stringly.SQL String condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewCitizenAppeals where(@Stringly.SQL String condition, Object... binds) {
        return where(DSL.condition(condition, binds));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewCitizenAppeals where(@Stringly.SQL String condition, QueryPart... parts) {
        return where(DSL.condition(condition, parts));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewCitizenAppeals whereExists(Select<?> select) {
        return where(DSL.exists(select));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewCitizenAppeals whereNotExists(Select<?> select) {
        return where(DSL.notExists(select));
    }
}
