/*
 * Copyright (C) 2023 ctecinf.com.br
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package br.com.ctecinf;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
 *
 * @author Cássio Conceição
 * @since 01/11/2023
 * @version 2311
 * @see http://ctecinf.com.br/
 */
public class Email {

    public static final String URL_API_EMAIL = "http://ctecinf.com.br/api/email.php";

    /**
     * Envia email
     *
     * @param to Para
     * @param subject Assunto
     * @param message Mensagem
     * @param attachment Anexos
     * @return String
     * @throws java.io.IOException
     */
    public static String send(String to, String subject, String message, File... attachment) throws IOException {
        return Email.send(to, "suporte@ctecinf.com.br", subject, message, attachment);
    }

    /**
     * Envia email
     *
     * @param to Para
     * @param from De
     * @param subject Assunto
     * @param message Mensagem
     * @param attachment Anexos
     * @return String
     * @throws java.io.IOException
     */
    public static String send(String to, String from, String subject, String message, File... attachment) throws IOException {
        Post post = Post.from(Email.URL_API_EMAIL);
        post.addData("to", to);
        post.addData("from", from);
        post.addData("subject", subject);
        post.addData("message", message);
        for (File file : attachment) {
            post.addData(file.getName().split("\\.")[0], file);
        }
        return post.finish().toString(Charset.defaultCharset());
    }
}
