// Path: src/main/java/org/chorem/ecd/dao/PersonDao.java
// @ApplicationScoped
// public class PersonDao extends AbstractDao<org.chorem.ecd.model.Person, Integer> {
// 
//     public PersonDao() {
//         super(Person.class, PERSON, PERSON.ID::eq);
//     }
// 
//     public void addPerson(org.chorem.ecd.model.Person person) {
//         DSLContext create = dataSource.getSqlContext();
//         PersonRecord personRecord = create.newRecord(PERSON);
//         personRecord.setName(person.getName());
//         personRecord.store();
//     }
// }
// 
// Path: src/main/java/org/chorem/ecd/model/Person.java
// public class Person {
// 
//     private int id;
// 
//     private String name;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// }


import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.Payload;
import com.google.common.base.Strings;
import org.chorem.ecd.dao.PersonDao;
import org.chorem.ecd.dao.TransactionRequired;
import org.chorem.ecd.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.io.UnsupportedEncodingException;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
package org.chorem.ecd.service;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@ApplicationScoped
public class AuthService {

    private static final Logger logger = LoggerFactory.getLogger(AuthService.class);

    @Inject
    private PersonDao personDao;

    private final Algorithm algorithm;

    private final JWTVerifier verifier;

    public AuthService() throws UnsupportedEncodingException {
        algorithm = Algorithm.HMAC512("secretpassphrase");
        verifier = JWT.require(algorithm).withIssuer("auth0").build();
    }

    @TransactionRequired
    public String getSignedToken(String subject, String password) {
        if (Strings.isNullOrEmpty(subject) || Strings.isNullOrEmpty(password)) {
            return null;
        }

// Path: src/main/java/org/chorem/ecd/dao/PersonDao.java
// @ApplicationScoped
// public class PersonDao extends AbstractDao<org.chorem.ecd.model.Person, Integer> {
// 
//     public PersonDao() {
//         super(Person.class, PERSON, PERSON.ID::eq);
//     }
// 
//     public void addPerson(org.chorem.ecd.model.Person person) {
//         DSLContext create = dataSource.getSqlContext();
//         PersonRecord personRecord = create.newRecord(PERSON);
//         personRecord.setName(person.getName());
//         personRecord.store();
//     }
// }
// 
// Path: src/main/java/org/chorem/ecd/model/Person.java
// public class Person {
// 
//     private int id;
// 
//     private String name;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// }


// Path: src/main/java/org/chorem/ecd/service/AuthService.java
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.Payload;
import com.google.common.base.Strings;
import org.chorem.ecd.dao.PersonDao;
import org.chorem.ecd.dao.TransactionRequired;
import org.chorem.ecd.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.io.UnsupportedEncodingException;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;

package org.chorem.ecd.service;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@ApplicationScoped
public class AuthService {

    private static final Logger logger = LoggerFactory.getLogger(AuthService.class);

    @Inject
    private PersonDao personDao;

    private final Algorithm algorithm;

    private final JWTVerifier verifier;

    public AuthService() throws UnsupportedEncodingException {
        algorithm = Algorithm.HMAC512("secretpassphrase");
        verifier = JWT.require(algorithm).withIssuer("auth0").build();
    }

    @TransactionRequired
    public String getSignedToken(String subject, String password) {
        if (Strings.isNullOrEmpty(subject) || Strings.isNullOrEmpty(password)) {
            return null;
        }

        Person person = new Person();